
nnoremap <silent> <leader> :silent WhichKey '<Space>'<CR>
vnoremap <silent> <leader> :silent <c-u> :silent WhichKeyVisual '<Space>'<CR>

" Create map to add keys to
let g:which_key_map =  {}
" Define a separator
let g:which_key_sep = '→ '
" set timeoutlen=100

" Not a fan of floating windows for this
let g:which_key_use_floating_win = 0

" Change the colors if you want
highlight default link WhichKey          Operator
highlight default link WhichKeySeperator DiffAdded
highlight default link WhichKeyGroup     Identifier
highlight default link WhichKeyDesc      Function

" Hide status line
autocmd! FileType which_key
autocmd  FileType which_key set laststatus=0 noshowmode noruler
  \| autocmd BufLeave <buffer> set laststatus=2 noshowmode ruler

" Single mappings
let g:which_key_map['S'] = [ ':Startify'            , 'start screen' ]
let g:which_key_map['T'] = [ ':tabedit'             , 'new tab' ]
let g:which_key_map['h'] = [ '<c-w>h'               , 'move to the left window' ]
let g:which_key_map['j'] = [ '<c-w>j'               , 'move to the down window' ]
let g:which_key_map['k'] = [ '<c-w>k'               , 'move to the up window' ]
let g:which_key_map['l'] = [ '<c-w>l'               , 'move to the right window' ]
let g:which_key_map['1'] = [ ':UndotreeToggle'      , 'open Undotree' ]
let g:which_key_map['2'] = [ ':Vista!!'             , 'open Vista' ]
let g:which_key_map['3'] = [ ':RnvimrToggle'        , 'open ranger' ]
let g:which_key_map['4'] = [ ':CocCommand explorer' , 'open Coc-Explorer' ]
let g:which_key_map['['] = [ ''                     , 'add empty line above']
let g:which_key_map[']'] = [ ''                     , 'add empty line under']

let g:which_key_map.c = {
  \ 'name' : '+Coc' ,
  \ 'n': ['<Plug>(coc-rename)' , 'Rename the current variable'],
  \ 'F': ['<Plug>(coc-fix-current)' , 'Auto fix current error'],
  \ 'f': ['' , 'Formatting selected code'],
  \ 'x': ['' , 'Convert visual selected code to snippet'],
  \ 'd': [':call CocAction("diagnosticToggle")' , 'Diagnostic Toggle'],
  \ }

let g:which_key_map.d = {
  \ 'name' : "+Debuger",
  \ 'd' : ['','Debuger gdb'],
  \ 'l' : ['','Debuger lldb'],
  \ 'c' : ['','Compile C++'],
  \ 'r' : ['','Run C++'],
  \ }

let g:which_key_map.g = {
  \ 'name' : '+GoTo' ,
  \ 'V' : ['<c-w><c-f>'     , 'GoTo file vetrically'],
  \ 'H' : ['<c-w><c-f><c-w>j<c-w>H'     , 'GoTo file horizontally'],
  \ 'n' : [':tabe <cfile>'          , 'GoTo file in new teb'],
  \ }

let g:which_key_map.m = {
  \ 'name' : '+MarkDown' ,
  \ 'q' : ['<Plug>MarkdownPreview', 'Start Preview'],
  \ 'w' : ['<Plug>MarkdownPreviewStop', 'Stop Preview'],
  \ 'e' : ['<Plug>MarkdownPreviewToggle', 'Toggle Preview'],
  \ 'm' : [''                                               , 'Table mode Toggle'],
  \ 't' : [''                                               , 'Table mode-Tableize'],
  \ }

let g:which_key_map.t = {
  \ 'name' : '+terminal' ,
  \ ';' : [':FloatermNew --wintype=popup --height=6'        , 'terminal'],
  \ 'b' : [':Tabularize'                                    , 'Tabularizer'],
  \ 'f' : [':FloatermNew fzf'                               , 'fzf'],
  \ 'g' : [':FloatermNew lazygit'                           , 'git'],
  \ }

let g:which_key_map.w = {
  \ 'name' : '+Windows' ,
  \ 'n' : [':split'          , 'Split_horizontally'],
  \ 'v' : [':vsplit'         , 'Split_vertically'],
  \ 'H' : ['<c-w>j<c-w>H'    , 'Change to horizontal'],
  \ 'V' : ['<c-w>h<c-w>K'    , 'Change to vertical'],
  \ 'x' : ['<c-w>x'          , 'Switch the windows'],
  \ 'o' : [':on'             , 'Close other window'],
  \ }

" Register which key map
call which_key#register('<Space>', "g:which_key_map")
